package com.ssm.studen.controller;

import com.ssm.studen.model.Examquestionpaper;
import com.ssm.studen.service.ExamquestionpaperService;
import com.ssm.studen.tool.ResponseMessage;
import com.ssm.studen.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 试卷考题表：
 *          对外提供数据服务接口
 */
@Api(tags = "examquestionpaper")
@RestController
public class ExamquestionpaperController {

    @Autowired
    private ExamquestionpaperService examquestionpaperService;

    /********************试卷考题表的更新*********************/
    @ApiOperation("更新")
    @RequestMapping("/updateExamQuestionpaper")
    public ResponseMessage updateExamQuestionpaper(Examquestionpaper examquestionpaper){
        //传入的参数不能为空
        if(examquestionpaper != null){
            //参数当中主键不能为0
            if(examquestionpaper.getEqpnum() != 0){
                if(examquestionpaperService.updateExamQuestionpaper(examquestionpaper) == 1){
                    if(examquestionpaper.getEpnum()!=0||
                            examquestionpaper.getQnum()!=0||
                            examquestionpaper.getSequencelist()!=0||
                            examquestionpaper.getEqptype()!=null){
                        examquestionpaperService.updateExamQuestionpaper(examquestionpaper);
                    }
                    return Result.success("更新成功");
                }else{
                    return Result.error("更新失败");
                }
            }
        }
        return Result.error("传入参数不正确");
    }


    /********************试卷考题表的查询*************************/
    @ApiOperation("试卷考题表的查询")
    @RequestMapping(value = "/selectExamQuestionpaper",method = RequestMethod.PUT)
    public ResponseMessage selectExamQuestionpaper(int eqpnum){
        Map<String,List> map = new HashMap<>();
        List<Examquestionpaper> listExamquestionpaper = examquestionpaperService.selectExamQuestionpaper(eqpnum);
        map.put("list",listExamquestionpaper);
        return Result.success("200",map);
    }
}
